#!/usr/bin/env python
# -*- coding: Latin-1 -*-
from jatek import *
import sys
import os
def ment (tabla, sor, oszlop, lepes, filename, nyelv):
	param=sys.argv[0]
	konyvtar=os.path.dirname(param)
	if (konyvtar ==""):
		save =nyelv+'/data/game.sp'
	else:
		home=os.getenv('HOME') 
		if (str(home)=='None'):
			save=os.path.dirname(param)+'/'+nyelv+'/data/game.sp'
		else:
			save =home+'/.local/share/tilitoli/'+nyelv+'/data/game.sp'
		if not os.path.exists(os.path.dirname(save)):
			os.system('mkdir -p '+os.path.dirname(save))
	i, j =0, 0
	fajl =open(save, 'w')
	fajl.write(str(sor)+'\t'+str(oszlop)+'\n'+str(lepes)+'\n'+filename+'\n')
	for i in range(sor):
		for j in range(oszlop):
			fajl.write(tabla[i][j])
			if (j<oszlop-1):
				fajl.write('\t')
		if (i<sor-1):
			fajl.write('\n')
	fajl.close()

def betolt(nyelv):
	param=sys.argv[0]
	konyvtar=os.path.dirname(param)
	if (konyvtar ==""):
		save =nyelv+'/data/game.sp'
	else:
		home=os.getenv('HOME') 
		if (str(home)=='None'):
			save=os.path.dirname(param)+'/'+nyelv+'/data/game.sp'
		else:
			save =home+'/.local/share/tilitoli/'+nyelv+'/data/game.sp'
	i, j =0, 0
	ret =[]
	try:
		fajl =open(save, 'r')
	except:
		ret.append(int(0))
		return ret
	s =fajl.readline()
	sor =int(s[0])
	oszlop =int(s[2])
	lepes =int(fajl.readline())
	file =fajl.readline()
	filename =file.replace("\n","")
	tabla =[]
	for i in range(sor):
		tabla.append([])
		s =fajl.readline()
		a =s.replace("\n","")
		elem =a.split('\t')
		for j in range(oszlop):
			tabla[i].append(elem[j])
	ret.append(tabla)
	ret.append(lepes)
	ret.append(filename)
	return ret
